package com.liuf.thread.runable;

/**
 * @author LIUFANG
 * ThreadPoolExecutor
 */
public class RunnableDemo implements Runnable{

    private int ticketCount = 5;

    @Override
    public void run() {
        while(ticketCount > 0){
            System.out.println("剩余票数"+ticketCount);
            try {
                /**线程睡一下，方便抢资源*/
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            ticketCount--;
            System.out.println(Thread.currentThread().getName()+"卖掉一张票，剩余票数"+ticketCount);
        }
    }

    public static void main(String[] args){
        RunnableDemo rt = new RunnableDemo();
        new Thread(rt).start();
        new Thread(rt).start();
        new Thread(rt).start();
        new Thread(rt).start();
    }

}
